{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "%load_ext autoreload\n",
    "%autoreload 2"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 1. Generate similarity graph from hierarchies\n",
    "- outputs `demo/demo_similarty_graph.txt`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Similarity graph saved: demo/demo_similarty_graph.txt\n"
     ]
    }
   ],
   "source": [
    "from DREAMwalk.generate_similarity_net import save_sim_graph\n",
    "\n",
    "networkf='demo/demo_graph.txt'\n",
    "hierf='demo/demo_hierarchy.csv'\n",
    "simf='demo/demo_similarty_graph.txt'\n",
    "cutoff=0.4\n",
    "\n",
    "save_sim_graph(networkf=networkf,hierf=hierf,outputf=simf,cutoff=cutoff)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 2. Generate node embeddings by teleport-guided randomwalk\n",
    "- outputs `demo/embedding_file.pkl`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "random seed with 42\n",
      "Reading network files...\n",
      "Training edge type transition matrix...\n",
      "Generating paths...\n",
      "Generating node embeddings...\n",
      "Node embeddings saved: demo/embedding_file.pkl\n"
     ]
    }
   ],
   "source": [
    "from DREAMwalk.generate_embeddings import save_embedding_files\n",
    "\n",
    "# node type file should be given for application of heterogeneous Skip-gram\n",
    "nodetypef='demo/demo_nodetypes.tsv'\n",
    "embeddingf='demo/embedding_file.pkl'\n",
    "\n",
    "save_embedding_files(netf=networkf,sim_netf=simf, outputf=embeddingf,\n",
    "                    nodetypef=nodetypef,tp_factor=0.3)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 3. Predict drug-disease association\n",
    "- saves XGBoost classifier in `demo/clf.pkl`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "random seed with 42\n",
      "TRAIN set | Acc: 50.00% | AUROC: 0.5000 | AUPR: 0.5000 | F1-score: 0.6667\n",
      "VALID set | Acc: 50.00% | AUROC: 0.5000 | AUPR: 0.5000 | F1-score: 0.6667\n",
      "TEST  set | Acc: 50.00% | AUROC: 0.5000 | AUPR: 0.5000 | F1-score: 0.6667\n",
      "saved XGBoost classifier: demo/clf.pkl\n",
      "==================================================\n"
     ]
    }
   ],
   "source": [
    "from DREAMwalk.predict_associations import predict_dda\n",
    "\n",
    "pairf='demo/demo_dda.tsv'\n",
    "modelf='demo/clf.pkl'\n",
    "\n",
    "predict_dda(embeddingf=embeddingf, pairf=pairf, modelf=modelf)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "dreamwalk_test",
   "language": "python",
   "name": "dreamwalk"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.16"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
